<?php
include_once '../includes/common.php';
$proid = intval($_GET['proid']);
$url = daddslashes($_GET['url']);
$authcode = daddslashes($_GET['authcode']);
$program = $DB->get_row("SELECT * FROM authguao_program WHERE id='$proid' limit 1");
$siterow = $DB->get_row("SELECT * FROM authguao_site WHERE proid='$proid' and url='$url' limit 1");
if(!$siterow){
    $url = "*.".get_host($url);
    $siterow = $DB->get_row("SELECT * FROM authguao_site WHERE proid='$proid' and url='*.".get_host($url)."' limit 1");
}
if (!$proid) {
    $result=array("code"=>-1,"msg"=>'程序识别码错误！');
} else if (strlen($authcode)!=32 || !$authcode) {
    $result=array("code"=>-1,"msg"=>'授权码错误！');
} else if (!$program) {
    $result=array('code'=>-1,'msg'=>'授权平台不存在该程序！');
} else if ($authcode != $siterow['authcode']) {
    $result=array("code"=>-1,"msg"=>'授权KEY验证失败，请检查配置！');
} else if ($siterow['active'] != 1) {
    $result=array("code"=>-1,"msg"=>'很抱歉您的站点已被禁封！');
} else {
    if ($conf['active_program'] == 1) {
        if ($program['active'] == 0) {
            $result=array("code"=>-1,"msg"=>'很抱歉您的站点已停止运行！');
        }
    } else {
        if ($ver) {
            if ($program['update'] == 1) {
                if($ver >= $program['version']) {
                    $msg='<font color="green">您使用的程序：'.$program['name'].'，已是最新版本！</font><br/>当前版本：'.$program['ver'].' (Build '.$program['version'].')';
                } else {
                    $msg='<font color="red">您使用的程序：'.$program['name'].'，发现新版本(～￣▽￣)～！</font> 最新版本：'.$program['ver'].' (Build '.$program['version'].')';
                }
            } else {
                $msg='<font color="blue">公告服务器正在维护，请稍后访问！</font>';
            }
        } else {
            $msg='<font color="blue">公告服务器正在维护，请稍后访问！</font>';
        }
        $result=array("code"=>1,"msg"=>$msg.'</hr>'.$program['api_notice']);
    }
}
echo json_encode($result);
$DB->close();